﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;

namespace SqlSugarRepository
{
    /// <summary>
    /// 拉姆达表达示操作
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface ISugarQueryable<T>
    {
        /// <summary>
        /// 存储queryable的对象
        /// </summary>
        object QueryableCore { get; set; }
        /// <summary>
        /// 联表查询
        /// </summary>
        /// <typeparam name="T2">联接的表对象</typeparam>
        /// <param name="expression">表达式</param>
        /// <param name="type">Join的类型</param>
        /// <returns></returns>
        ISugarQueryable<T> JoinTable<T2>(Expression<Func<T, T2, object>> expression, JoinType type = JoinType.Left);
        /// <summary>
        /// 联表查询
        /// </summary>
        /// <typeparam name="T2">联接表的对象</typeparam>
        /// <typeparam name="T3">联接表的对象</typeparam>
        /// <param name="expression">表达式</param>
        /// <param name="type">Join的类型</param>
        /// <returns></returns>
        ISugarQueryable<T> JoinTable<T2, T3>(Expression<Func<T, T2, T3, object>> expression, JoinType type = JoinType.Left);
        /// <summary>
        /// 获取最大值
        /// </summary>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="maxField">列名</param>
        /// <returns></returns>
        TResult Max<TResult>(string maxField);
        /// <summary>
        /// 获取最小值
        /// </summary>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="minField">列名</param>
        /// <returns></returns>
        TResult Min<TResult>(string minField);
        /// <summary>
        /// 排序
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <param name="expression">例如 (s1,s2)=>s1.id,相当于 order by s1.id</param>
        /// <param name="type">排序类型</param>
        /// <returns></returns>
        ISugarQueryable<T> OrderBy<T2>(Expression<Func<T, T2, object>> expression, OrderByType type = OrderByType.Asc);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns></returns>
        ISugarQueryable<TResult> Select<TResult>(Expression<Func<T, TResult>> expression);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T2">返回值的新实体类型</typeparam>
        /// <param name="select">查询字符串（例如 id,name）</param>
        /// <returns></returns>
        ISugarQueryable<T2> Select<T2>(string select);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T2">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns></returns>
        ISugarQueryable<TResult> Select<T2, TResult>(Expression<Func<T, T2, TResult>> expression);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T2">原数据实体类型</typeparam>
        /// <typeparam name="T3">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns></returns>
        ISugarQueryable<TResult> Select<T2, T3, TResult>(Expression<Func<T, T2, T3, TResult>> expression);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T2">原数据实体类型</typeparam>
        /// <typeparam name="T3">原数据实体类型</typeparam>
        /// <typeparam name="T4">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns></returns>
        ISugarQueryable<TResult> Select<T2, T3, T4, TResult>(Expression<Func<T, T2, T3, T4, TResult>> expression);
        /// <summary>
        /// 将源数据对象转换到新对象中
        /// </summary>
        /// <typeparam name="T2">原数据实体类型</typeparam>
        /// <typeparam name="T3">原数据实体类型</typeparam>
        /// <typeparam name="T4">原数据实体类型</typeparam>
        /// <typeparam name="T5">原数据实体类型</typeparam>
        /// <typeparam name="TResult">返回值的新实体类型</typeparam>
        /// <param name="expression">给新实体赋值的表达式</param>
        /// <returns></returns>
        ISugarQueryable<TResult> Select<T2, T3, T4, T5, TResult>(Expression<Func<T, T2, T3, T4, T5, TResult>> expression);
        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <param name="expression">表达式条件</param>
        /// <returns></returns>
        ISugarQueryable<T> Where<T2>(Expression<Func<T, T2, bool>> expression);
        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <param name="whereString">Where后面的Sql条件语句 (例如： id=@id )</param>
        /// <param name="whereObj">匿名参数 (例如：new{id=1,name="张三"})</param>
        /// <returns></returns>
        ISugarQueryable<T> Where<T2>(string whereString, object whereObj = null);
        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <typeparam name="T3">表实体类型</typeparam>
        /// <param name="expression">表达式条件</param>
        /// <returns></returns>
        ISugarQueryable<T> Where<T2, T3>(Expression<Func<T, T2, T3, bool>> expression);
        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <typeparam name="T3">表实体类型</typeparam>
        /// <typeparam name="T4">表实体类型</typeparam>
        /// <param name="expression">表达式条件</param>
        /// <returns></returns>
        ISugarQueryable<T> Where<T2, T3, T4>(Expression<Func<T, T2, T3, T4, bool>> expression);
        /// <summary>
        /// 条件筛选
        /// </summary>
        /// <typeparam name="T2">表实体类型</typeparam>
        /// <typeparam name="T3">表实体类型</typeparam>
        /// <typeparam name="T4">表实体类型</typeparam>
        /// <typeparam name="T5">表实体类型</typeparam>
        /// <param name="expression">表达式条件</param>
        /// <returns></returns>
        ISugarQueryable<T> Where<T2, T3, T4, T5>(Expression<Func<T, T2, T3, T4, T5, bool>> expression);
    }
}
